package models

import (
	"time"
	"user_srv/basic/config"
)

// SwipeCandidate 滑动候选用户表：存储推荐给用户的候选用户
// 表名：swipe_candidate
type SwipeCandidate struct {
	Id          uint64    `gorm:"column:id;type:bigint UNSIGNED;primaryKey;not null;" json:"id"`
	UserId      uint64    `gorm:"column:user_id;type:bigint UNSIGNED;index;not null;comment:用户ID;" json:"user_id"`
	CandidateId uint64    `gorm:"column:candidate_id;type:bigint UNSIGNED;index;not null;comment:候选用户ID;" json:"candidate_id"`
	MatchScore  float64   `gorm:"column:match_score;type:decimal(5,4);default:0;comment:匹配分数;" json:"match_score"`
	Reason      string    `gorm:"column:reason;type:varchar(100);default:NULL;comment:推荐理由;" json:"reason"`
	Status      int8      `gorm:"column:status;type:tinyint(1);default:1;comment:状态 1-待滑动 2-已滑动 3-已过期;" json:"status"`
	CreatedAt   time.Time `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt   time.Time `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt   time.Time `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

// TableName 返回 SwipeCandidate 对应的数据库表名："swipe_candidate"
func (SwipeCandidate) TableName() string {
	return "swipe_candidate"
}

// GetByUser 根据用户ID获取候选用户列表
func (s *SwipeCandidate) GetByUser() ([]SwipeCandidate, error) {
	var candidates []SwipeCandidate
	err := config.DB.Where("user_id = ? AND status = 1", s.UserId).Order("match_score DESC").Find(&candidates).Error
	return candidates, err
}

// Create 创建候选用户记录
func (s *SwipeCandidate) Create() error {
	return config.DB.Create(&s).Error
}

// Delete 删除候选用户记录
func (s *SwipeCandidate) Delete() error {
	return config.DB.Delete(&s).Error
}
